package org.sith.taskrunner.filters.filters;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

public class LogoutFilter implements Filter {

	public void destroy() {
		
	}

	@Override
	public void doFilter(ServletRequest req, ServletResponse resp,
			FilterChain chain) throws IOException, ServletException {
		HttpServletRequest request = (HttpServletRequest) req;
        HttpServletResponse response = (HttpServletResponse) resp;
        HttpSession session = request.getSession();
        session.invalidate();
        String contextPath = session.getServletContext().getContextPath();
        response.sendRedirect(contextPath+"/login.jsp");
	}

	@Override
	public void init(FilterConfig arg0) throws ServletException {
		
	}

}
